'use strict';
const BaseController = require('../base');
const jwt = require('jsonwebtoken');
class RouterController extends BaseController {
  static get serviceName() {
    return 'business.user';
  }

  async wxLogin() {
    let user = await this.service.wxLogin(this.ctx.request.body);
    user.token = jwt.sign(user, this.config.keys);
    this.ctx.success(user);
  }
  async getUserQrCode() {
    const user = await this.service.getUserQrCode(this.ctx.query);
    this.ctx.success(user);
  }

  async show() {
    const { ctx } = this;
    const id = ctx.params.id;
    const result = await this.service.findById(id);
    if (!result) {
      ctx.error(401, '登录过期！');
      return
    }
    if (result.status === 0) {
      ctx.error(500, '账号状态异常！');
    }
    ctx.success(result);
  }
  async getUserQrCode() {
    const user = await this.service.getUserQrCode(this.ctx.query);
    this.ctx.success(user);
  }

  async getPhoneNumber() {
    const user = await this.service.getPhoneNumber(this.ctx.request.body);
    this.ctx.success(user);
  }
}
module.exports = RouterController;
